/**************************************************************************************************************
 * @copyright Copyright (c) 2015—2024 Uniorange Internet Design Co., LTD. All rights reserved.
 * @author Uniorange Internet Design Co., LTD.
 *
 * This file is part of the App project. Copyright © Uniorange Internet Design Co., Ltd. All Rights Reserved.
 * Unauthorized copying of this file, via any medium is strictly prohibited Proprietary and confidential.
 *
 **************************************************************************************************************/
package com.jinyu.core.codec;

import com.jinyu.core.protocol.RegisterProtocol;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;

/**
 * @author 邱金波
 * @version V0.1
 * @className Codec
 * @description 协议编解码
 * @date 2024/09/19 10:10
 */
public class MyLengthFieldBasedFrameDecoder extends LengthFieldBasedFrameDecoder {
    private final static int MAX_FRAME_LENGTH = 10 * 1024;

    public MyLengthFieldBasedFrameDecoder() {
        super(MAX_FRAME_LENGTH, 0, 4, 0, 4);
    }

    @Override
    protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
        in = (ByteBuf) super.decode(ctx, in);
        if (in == null) {
            return null;
        }
        return in;
    }
}
